package com.leeyu.rabbitmq.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {

    public static final String ORDER_PLACE_EXCHANGE = "order_place_exchange";
    public static final String COUPON_QUEUE = "coupon_queue";
    public static final String USER_POINTS_QUEUE = "user_points_queue";
    public static final String BUSINESS_QUEUE = "business_queue";

    @Bean
    public Exchange orderPlaceExchange() {
        return ExchangeBuilder.fanoutExchange(ORDER_PLACE_EXCHANGE).build();
    }

    @Bean
    public Queue couponQueue(){
        return QueueBuilder.durable(COUPON_QUEUE).build();
    }

    @Bean
    public Queue userPointsQueue(){
        return QueueBuilder.durable(USER_POINTS_QUEUE).build();
    }

    @Bean
    public Queue businessQueue(){
        return QueueBuilder.durable(BUSINESS_QUEUE).build();
    }

    @Bean
    public Binding couponBinding(Exchange orderPlaceExchange, Queue couponQueue){
        return BindingBuilder.bind(couponQueue).to(orderPlaceExchange).with("").noargs();
    }

    @Bean
    public Binding userPointsBinding(Exchange orderPlaceExchange, Queue userPointsQueue){
        return BindingBuilder.bind(userPointsQueue).to(orderPlaceExchange).with("").noargs();
    }

    @Bean
    public Binding businessBinding(Exchange orderPlaceExchange, Queue businessQueue){
        return BindingBuilder.bind(businessQueue).to(orderPlaceExchange).with("").noargs();
    }
}
